<template>
	<view class="scrool-page">
		<view class="file-list">
			<block v-for="(msg, i) in msgs" :key="i">
				<view class="file-item" @click="gotoDetail(msg)">

					<view class="file-item-left">
						<view class="file-name">{{msg.articleTitle}}</view>
						<view class="file-createtime">{{msg.updateTime | dateFormat}}</view>
					</view>
					<view class="file-item-right">
						<view v-if="msg.isread==0" class="dot"></view>
					</view>
				</view>
			</block>
			<u-divider v-show="pageNum >= totalPages">没有更多了</u-divider>
		</view>
		<u-tabbar v-model="current" :list="tablist" :beforeSwitch="beforeSwitch" :mid-button="true"></u-tabbar>
		<u-popup v-model="show" mode="bottom">

			<view class="contentBox">
				<!-- <image class="logo" :class="{'active':active}" src="../../static/nav_icon/fenxiang@2x.png"  mode="aspectFit"></image> -->
				<view class="tabbar-box-wrap">
					<view class="tabbar-box">
						<view class="tabbar-box-item" @click="goToPage('/subpackage/technology_share/share_new')">
							<image class="box-image" src="../../static/nav_icon/fenxiang@2x.png" mode="aspectFit">
							</image>
							<text class="explain">技术分享</text>
						</view>
						<view class="tabbar-box-item" @click="goToPage('/subpackage/technology_share/share_new_fault')">
							<image class="box-image" src="../../static/nav_icon/shebeifuwu@2x.png" mode="aspectFit">
							</image>
							<text class="explain">消缺支援</text>
						</view>
						<view class="tabbar-box-item" @click="goToPage('/subpackage/wind/build/build_demand')">
							<image class="box-image" src="../../static/nav_icon/offshore_wind.png" mode="aspectFit">
							</image>
							<text class="explain">建设需求</text>
						</view>
						<view class="tabbar-box-item" @click="goToPage('/subpackage/wind/build/build_service')">
							<image class="box-image" src="../../static/nav_icon/secondarymarket@3x.png"
								mode="aspectFit"></image>
							<text class="explain">设备服务</text>
						</view>
					</view>
					<view class="close_dialog">
						<view class="closeBox" @click="beforeSwitch(2)">
							<u-icon name="close"></u-icon>
						</view>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				msgs: [

				],
				pageNum: 1,
				pageSize: 10,
				totalPages: 0, //总页数
				total: '', //总条数
				tablist: [

					{
						iconPath: "/static/tabbar_icon/home@2x.png",
						selectedIconPath: "/static/tabbar_icon/home-active@2x.png",
						text: '首页',
						customIcon: false,
						pagePath: "/pages/home/home",
					},
					{
						iconPath: "/static/tabbar_icon/topic@2x.png",
						selectedIconPath: "/static/tabbar_icon/topic-active@2x.png",
						text: '话题',
						pagePath: "/pages/topic/topic",
					},
					{
						iconPath: "https://cdn.uviewui.com/uview/common/min_button.png",
						selectedIconPath: "https://cdn.uviewui.com/uview/common/min_button_select.png",
						text: '发布',
						midButton: true,
						customIcon: false,
					},
					{
						iconPath: "/static/tabbar_icon/message@2x.png",
						selectedIconPath: "/static/tabbar_icon/message-active@2x.png",
						text: '消息',
						customIcon: false,
						isDot: false,
						count: 0,
						pagePath: "/pages/commentsmsg/commentsmsg",
					},
					{
						iconPath: "/static/tabbar_icon/my@2x.png",
						selectedIconPath: "/static/tabbar_icon/my-active@2x.png",
						text: '我的',

						isDot: false,
						customIcon: false,
						pagePath: "/pages/myuser/myuser",
					},
				],
				show: false,

			};
		},
		filters: {
			//过滤器 用于格式化时间
			dateFormat: function(value) {

				var result = value.slice(0, 10);
				return result;
			},
		},
		onLoad() {
			var that = this;
			this.timer = setInterval(() => {

				if (this.$store.state.isLogin) {
					this.$u.api.getWindCommentsMsgDots({
							userId: this.$store.state.userinfo.id,
						})
						.then(res => {

							if (res.data > 0) {
								that.tablist[3].isDot = true;

								that.tablist[3].count = 1;

							} else {
								that.tablist[3].isDot = false;

								that.tablist[3].count = 0;
							}

						});
				}

			}, 5000);


		},
		onShow() {
			this.pageNum = 1;
			this.getWindCommentsMsgs();
		},
		methods: {
			goToPage(url) {
				if (!url) return;
				uni.navigateTo({
					url
				});
			},
			beforeSwitch(index) {
				if (index == 2) {
					this.show = !this.show;
				}
				return true;
			},


			/**
			 * 下拉刷新回调函数
			 */
			onPullDownRefresh() {

				this.pageNum = 1;
				this.getWindCommentsMsgs();
				setTimeout(function() {
					uni.stopPullDownRefresh();
				}, 500);

			},
			/**
			 * 上拉加载更多
			 */
			onReachBottom() {
				// console.log("上拉加载更多" + this.pageNum + "  " + this.totalPages)
				if (this.pageNum >= this.totalPages) {
					return
				}

				// 加载更多数据
				this.pageNum++;
				this.getWindCommentsMsgs();


			},

			gotoDetail(item) {
				var that = this;
				this.$u.api.setWindCommentsMsgs({
						msgId: item.msgId,

					})
					.then(res => {
						for (let i = 0; i < that.msgs.length; i++) {
							if (that.msgs[i].msgId == item.msgId) {
								that.msgs[i].isread = 1;
							}
						}
					});

				if (item.commentType == 1) {
					uni.navigateTo({
						url: '/subpackage/industry_dynamic_detail/industry_dynamic_detail?articleId=' + item
							.commentId
					})
				} else if (item.commentType == 3) {
					uni.navigateTo({
						url: '/subpackage/technology_share/shareDetail?shareId=' + item
							.commentId
					})
				} else if (item.commentType == 4) {
					uni.navigateTo({
						url: '/subpackage/technology_share/shareDetail_fault?shareId=' + item
							.commentId
					})
				}

			},

			getWindCommentsMsgs() {

				this.$u.api.getWindCommentsMsgs({
						pageNum: this.pageNum,
						pageSize: this.pageSize,
						userId: this.$store.state.userinfo.id,
					})
					.then(res => {

						this.total = res.total;
						this.totalPages = res.totalPages;
						var resultList = res.rows;
						if (this.pageNum == 1) {
							this.msgs = resultList;
						} else {
							this.msgs = this.msgs.concat(resultList);
						}
					});
			}
		}
	}
</script>
<style lang="scss">
	page {
		width: 100%;
		height: 100%;
	}

	.scrool-page {
		display: flex;
		flex-direction: column;
		width: 100%;
		height: 100%;
	}

	.flie-header-box {
		flex-shrink: 0; //保持内容不缩放，适用于内容不确定大小时候
		// height:100rpx; //设置高度为100，如果内容确定为这么高的话

		background-color: #3BA2FF;
		padding-top: 24rpx;
		padding-bottom: 24rpx;
		padding-left: 20rpx;
		padding-right: 20rpx;
		align-items: center;
		justify-content: center;
		display: flex;
	}

	.file-list {
		flex-grow: 1; //充满屏幕
		height: 100vh; //如果中间不充满屏幕的话，自适应，底部会跟随在中间布局后面
		overflow: auto;
		background-color: #F7F7F7;
	}

	.file-item {
		display: flex;
		margin: 10rpx 15rpx;
		padding: 10rpx 5rpx;
		border-radius: 8rpx;
		background-color: #FFFFFF;
		align-items: center;
		justify-content: space-between;

		.file-item-left {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			margin-left: 10rpx;

			.file-name {
				font-size: 26rpx;
				font-family: PingFang SC;
				overflow: hidden;
				text-overflow: ellipsis; //文本溢出显示省略号
			}

			.file-createtime {
				font-size: 24rpx;
				font-family: PingFang SC;
				color: #999999;
			}
		}

		.file-item-right {
			.dot {
				width: 20rpx;
				height: 20rpx;
				border-radius: 50%;
				background-color: red;
				margin-right: 10rpx;
			}
		}
	}


	.contentBox {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		/* #ifdef H5 */
		height: calc(100vh - var(--window-bottom) - var(--window-top));
		/* #endif */
		/* #ifndef H5 */
		height: 100vh;
		/* #endif */
		transition: opacity 0.3s;
		background: #333333;

		// opacity: 0;
		// &.active {
		// 	opacity: 1;
		// }
		.logo {
			position: relative;
			margin-top: -400upx;
			width: 200upx;
			height: 200upx;
			// z-index: -1;
			opacity: 0;
			transition: opacity 0.3s;

			&.active {
				opacity: 1;
			}
		}
	}

	.tabbar-box-wrap {
		position: absolute;
		width: 100%;
		padding: 50upx;
		box-sizing: border-box;
		bottom: 0;
		left: 0;

		.tabbar-box {
			display: flex;
			flex-direction: column;
			align-items: center;
			position: relative;
			display: flex;
			width: 100%;
			// background: #fff;
			// border-radius: 20upx;
			padding: 15upx 20upx;
			box-sizing: border-box;
			z-index: 2;

			// box-shadow: 0px 2px 5px 2px rgba(0, 0, 0, 0.1);
			// &:after {
			// 	content: '';
			// 	position: absolute;
			// 	bottom: -16upx;
			// 	left: 0;
			// 	right: 0;
			// 	margin: auto;
			// 	width: 50upx;
			// 	height: 50upx;
			// 	transform: rotate(45deg);
			// 	background: #fff;
			// 	z-index: 1;
			// 	box-shadow: 2px 2px 5px 1px rgba(0, 0, 0, 0.1);
			// 	border-radius: 2px;
			// }
			// &:before {
			// 	content: '';
			// 	position: absolute;
			// 	top: 0;
			// 	left: 0;
			// 	width: 100%;
			// 	height: 100%;
			// 	background: #ffffff;
			// 	border-radius: 20upx;
			// 	z-index: 2;
			// }
			.tabbar-box-item {
				display: flex;
				align-items: center;
				width: 46vw;
				//justify-content: center;
				// position: relative;
				// width: 100%;
				z-index: 3;
				margin: 40upx auto;
				color: $uni-color-subtitle;
				text-align: center;
				font-size: 100vw;
				justify-content: space-around;

				.box-image {
					width: 15vw;
					height: 15vw;
				}

				.explain {
					color: #FFFFFF;
					font-size: 7vw;
				}
			}
		}
	}

	.close_dialog {
		height: 100rpx;
		display: flex;
		justify-content: center;
		margin-top: 40rpx;

		.closeBox {
			background: #FFFFFF;
			margin: auto;
			border-radius: 50%;
			text-align: center;
			height: 100rpx;
			line-height: 100rpx;
			width: 100rpx;

		}
	}
</style>
